import type {
  StudentInfoItem,
  StudentInfoParams,
  StudyRecordItem,
  StudentOptionItem,
} from '@/types/studentInfo'
import type { PageResult } from '@/types/global'
import { http } from '@/utils/http'

/**
 * 获取学生基础信息列表
 * @param params
 * @returns
 */
export const getStudentBaseInfoList = (params: StudentInfoParams) => {
  return http<PageResult<StudentInfoItem>>({
    method: 'GET',
    url: '/wechat/student/base/list',
    data: params,
  })
}

/**
 * 获取学生信息列表
 * @param params
 * @returns
 */
export const getStudentInfoList = (params: StudentInfoParams) => {
  return http<StudentInfoItem[]>({
    method: 'GET',
    url: '/wechat/student/list',
    data: params,
  })
}

/**
 * 添加学习记录
 * @param params
 * @returns
 */
export const addStudyRecord = (params: StudyRecordItem) => {
  return http<StudyRecordItem>({
    method: 'POST',
    url: '/wechat/student/addStudyRecord',
    data: params,
  })
}

/**
 * 添加成长档案
 * @param params
 * @returns
 */
// 因找不到 GrowthArchiveItem 类型，先使用 any 类型临时替代，后续需补充该类型定义
export const addGrowthArchive = (params: any) => {
  return http<any>({
    method: 'POST',
    url: '/wechat/student/addGrowthArchive',
    data: params,
  })
}

/**
 * 获取学生选项信息列表
 * @param params
 * @returns
 */
export const getStudentOptionInfoList = (params: StudentInfoParams) => {
  return http<StudentOptionItem[]>({
    method: 'GET',
    url: '/wechat/student/getStudentOptionInfoList',
    data: params,
  })
}

/**
 * 更新学生积分
 * @param params
 * @returns
 */
export const updateStudentPointsAPI = (params: { id?: number; learningPoints: number }) => {
  return http({
    method: 'POST',
    url: '/wechat/student/updatePoints',
    data: params,
  })
}

/**
 * 批量签到
 * @param data
 * @returns
 */
export const batchSignIn = (data: { studentScheduleIds: string }) => {
  return http({
    method: 'POST',
    url: '/wechat/student/batchSignIn',
    data,
  })
}

/**
 * 添加学生
 * @param data
 * @returns
 */
export const addStudentAPI = (data: StudentInfoItem) => {
  return http<StudentInfoItem>({
    method: 'POST',
    url: '/wechat/student/add',
    data,
  })
}

/**
 * 校验学生姓名
 * @param data
 * @returns
 */
export const checkStudentNameUniqueAPI = (data: StudentInfoItem) => {
  return http<{ isUnique: boolean }>({
    method: 'POST',
    url: '/wechat/student/checkNameUnique',
    data,
  })
}

/**
 * 获取学生信息
 * @param id
 * @returns
 */
export const getStudentInfoAPI = (id: number) => {
  return http<StudentInfoItem>({
    method: 'GET',
    url: `/wechat/student/base/info/${id}`,
  })
}

/**
 * 更新学生信息
 * @param data
 * @returns
 */
export const updateStudentAPI = (data: StudentInfoItem) => {
  return http<StudentInfoItem>({
    method: 'POST',
    url: `/wechat/student/update`,
    data,
  })
}
